/**
 * @File		: Question.java
 * @Subject		: Holds information about a question
 * @author 		: Isaac Parenteau	locus2k@gmail.com
 * @Date		: October 12th, 2011
 * @Licence		: Licensed under the GPU LGPL
 */
package mil.cdc.utils;

import java.util.ArrayList;

public class Question {
 
	private String question;
	private ArrayList<String> choices;
	private int answer;
	private int selectedAnswer;
	private int id;
	
	/***
	 * Stores a question's information
	 * @param question The question to be asked
	 * @param choices The possible choices to choose from
	 * @param answer The answer to the question
	 * @param id The question's id
	 */
	public Question(String question, ArrayList<String> choices, int answer, int id){
		this.question = question;
		this.choices = choices;
		this.answer = answer;
		this.id = id;
	}
	
	/**
	 * Stores a questions information
	 * @param question The question to be asked
	 * @param choices The possible choices to choose from
	 * @param answer The answer to the question
	 */
	public Question(String question, ArrayList<String> choices, int answer) {
		this(question, choices, answer, -1);
	}
	
	/**
	 * Get the question to be asked.
	 * @return question
	 */
	public String getQuestion() {
		return question;
	}
	
	/**
	 * Gets the answer to the question
	 * @return answer
	 */
	public int getAnswer() {
		return answer;
	}
	
	/***
	 * Gets the choices 
	 * @return
	 */
	public ArrayList<String> getChioces() {
		return choices;
	}
	
	/**
	 * Get a choice at a given index;
	 * @param index
	 * @return
	 */
	public String getChoice(int index) {
		if (index > choices.size()) { 
			return "";
		}
		return choices.get(index);
	}
	
	/***
	 * Get the selected answer
	 * @return selectedAnswer
	 */
	public int getSelectedAnswer() {
		return selectedAnswer;
	}
	
	/***
	 * Sets the selected answer
	 * @param selectedAnswer Selected answer
	 */
	public void setSelectedAnswer(int selectedAnswer){
		this.selectedAnswer = selectedAnswer;
	}
	
	/***
	 * Get the id of the question
	 * @return
	 */
	public int getID(){
		return id;
	}
	
	/**
	 * Sets the questions Id
	 * @param id
	 */
	public void setID(int id){
		this.id = id;
	}
	
	@Override
	/**
	 * Human readable output for the question
	 */
	public String toString() {
		StringBuilder builder = new StringBuilder();

        builder.append("Question ID: " + id + "\n");
        builder.append(question + "\n");

        for (String s : choices)
            builder.append("\t" + s + "\n");

        builder.append("Answer: " + answer);

        if (selectedAnswer != 0)
            builder.append("\nSelected Answer: " + selectedAnswer + "\n");

        return builder.toString();
	}
}
